/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ultrasoft.farmasoft.domain;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author Administrador		
 */
@Entity
@Table(name = "pharmacystock")
@NamedQueries({
    @NamedQuery(name = "Pharmacystock.findAll", query = "SELECT p FROM Pharmacystock p"),
    @NamedQuery(name = "Pharmacystock.findByPharmacyId", query = "SELECT p FROM Pharmacystock p WHERE p.pharmacystockPK.pharmacyId = :pharmacyId"),
    @NamedQuery(name = "Pharmacystock.findByStockId", query = "SELECT p FROM Pharmacystock p WHERE p.pharmacystockPK.stockId = :stockId"),
    @NamedQuery(name = "Pharmacystock.findByPharmacyIdByStockId", query = "SELECT p FROM Pharmacystock p WHERE p.pharmacystockPK.pharmacyId = :pharmacyId AND p.pharmacystockPK.stockId = :stockId"),
    @NamedQuery(name = "Pharmacystock.findByMain", query = "SELECT p FROM Pharmacystock p WHERE p.main = :main")})
public class Pharmacystock implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected PharmacystockPK pharmacystockPK;
    @Basic(optional = false)
    @Column(name = "main")
    private boolean main;
    @JoinColumn(name = "pharmacyId", referencedColumnName = "pharmacyId", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Pharmacy pharmacy;
    @JoinColumn(name = "stockId", referencedColumnName = "stockId", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Stock stock;

    public Pharmacystock() {
    }

    public Pharmacystock(PharmacystockPK pharmacystockPK) {
        this.pharmacystockPK = pharmacystockPK;
    }

    public Pharmacystock(PharmacystockPK pharmacystockPK, boolean main) {
        this.pharmacystockPK = pharmacystockPK;
        this.main = main;
    }

    public Pharmacystock(int pharmacyId, int stockId) {
        this.pharmacystockPK = new PharmacystockPK(pharmacyId, stockId);
    }
    
    public Pharmacystock(Pharmacy pharmacy, Stock stock) {
        this.pharmacystockPK = new PharmacystockPK(pharmacy.getPharmacyId(),stock.getStockId());
    }
    
    public Pharmacystock(Pharmacy pharmacy, Stock stock, boolean main) {
        this.pharmacystockPK = new PharmacystockPK(pharmacy.getPharmacyId(),stock.getStockId());
        this.main = main;
    }

    public PharmacystockPK getPharmacystockPK() {
        return pharmacystockPK;
    }

    public void setPharmacystockPK(PharmacystockPK pharmacystockPK) {
        this.pharmacystockPK = pharmacystockPK;
    }

    public boolean getMain() {
        return main;
    }

    public void setMain(boolean main) {
        this.main = main;
    }

    public Pharmacy getPharmacy() {
        return pharmacy;
    }

    public void setPharmacy(Pharmacy pharmacy) {
        this.pharmacy = pharmacy;
    }

    public Stock getStock() {
        return stock;
    }

    public void setStock(Stock stock) {
        this.stock = stock;
    }
    /*
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (pharmacystockPK != null ? pharmacystockPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Pharmacystock)) {
            return false;
        }
        Pharmacystock other = (Pharmacystock) object;
        if ((this.pharmacystockPK == null && other.pharmacystockPK != null) || (this.pharmacystockPK != null && !this.pharmacystockPK.equals(other.pharmacystockPK))) {
            return false;
        }
        return true;
    }

    @Override*/
    public String toString() {
        return "com.ultrasoft.farmasoft.domain.Pharmacystock[ pharmacystockPK=" + pharmacystockPK + " ]";
    }
    
}
